<?php
	//error_reporting(0);
	
	//test si connecté
	include_once 'Util/includeAll.php';
	
	if(!isConnected())
	{
		echo("<meta http-equiv=\"refresh\" content=\"0; URL=./login.php\">");
		header('Location: login.php');
	}
	
	$myUser = getUser(true);
	
	//initialise la liste des contacts dans la combobox
	$ContactList = getContactsListDest();
	//initialise la liste des contacts dans le menu de contacts
	$_strContacts = getContactsListItems();
	
	
	getHead('TextFlex - Envoyez des SMS depuis le web !');
?>

<html>
<head>
		<script type="text/javascript">
		var currentDisplayedConversationID = 0;
				
		$(function() {
			var Contacts = [
				<?php echo($ContactList);?>
			];
			$( "#phoneNumber" ).autocomplete({
				source: Contacts
			});
		});
		
		$(function() {
			$("#envoiSMS").click(envoyerSMS());
		});

		
		function routine()
		{
			MaJAll();
			setTimeout(function() {routine();},5000);
		}

		function MaJAll()
		{
			MaJContactList();
			MaJConversation();
			MaJUserInfos();			
		}
		
		function pageChargee()
		{
			$("#logDivInfo").hide();
			$("#logDivError").hide();
			MaJAll();
			
			setTimeout(function() {routine();},5000);
		}
		
			
		</script> 
	</head>
	<body onLoad="pageChargee()">
   		<div id="warper_main">
        <header align="left">
            <div align="center" class="div_logo">
            	<a href="." alt="TextFlex">
	                <table>
	                    <tr>
	                        <td rowspan="2"><img src="img/logo.png" alt="logo" width="153" height="132" class="logoImg logoImg_Min" /></td>
	                        <td><h1 class="logoTxt logoTxt_Min">TextFlex</h1></td>
	                    </tr>
	                    <tr>
	                        <td><h2 class="logoTxtSec logoTxtSec_Min">Envoyez vos SMS depuis le web !</h2></td>
	                    </tr>
	                </table>
                </a>
          	</div>
            <div class="div_User_Infos blocGris" id="divUserInfo">

          	</div>
        </header>
        
        <section>
            <aside class="blocGris">
            	<h1>Contacts</h1>
                <!-- List des contacts -->
                <div id="contactList" class="scrollable" style="max-height : 626px;">                
                <?php 
                echo ($_strContacts);
                ?>
                </div>

            </aside>
    		<article>
    			<div class="blocGris conv_div" id="conversation">
    				<!-- Conversation ici -->
    			</div>
	            <div class="div_sender blocGris">
	              <input type="tel" name="phoneNumber" id="phoneNumber" class="SMSdest SMSform" placeholder="Nom ou numéro du destinataire"><br/>
	              <textarea name="txt" id="txt" class="SMStxt SMSform" rows="8"  onkeypress="if(event.keyCode==13 && event.shiftKey){envoyerSMS();}" placeholder="Votre texte ici"></textarea>
	          <br/><br/>
	          		<div align="center">
		                <div href="#" id="envoiSMS" class="buttonBleu" style="float : none; width: 150px; height : 45px; text-align: center;" onclick="envoieSMS();">
		                	<a>
			                	<span>Envoyer SMS</span><br/>
			                	<span style="font-size : 10px; font-family : Helvetica; text-decoration : none;">MAJ+ENTREE</span>
		                	</a>
		                </div>
		             </div>
	                <!-- <a href="#" class="buttonBleu" style="float:none;" onclick="test();">Test</a> -->
	            </div>
		        <div class="ui-state-highlight ui-corner-all" id="logDivInfo" style="margin-top: 20px; padding: 0 .7em;display:none;"> 
		            <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em; bottom: 0px"></span>
		            <span id="logInfo"></span> </p>
		        </div>
		        <div class="ui-state-error ui-corner-all" id="logDivError" style="padding: 0 .7em;display:none;"> 
		            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em; bottom: 0px"></span> 
		            <span id="logError"></span> </p>
		        </div>
	        </article>
        </section>
	</div>
	</body>
   
	</html>